import java.util.Random;
import java.util.Scanner;

public class Guessnumber {
    public static void main(String[] args) {

        Random rand = new Random();
        Scanner scan = new Scanner(System.in);
        String playAgain = "";
        do {
            int chances = 7;
            System.out.println("还有7次机会，请猜一个1-100之间的整数：");
            int answer = rand.nextInt(100) + 1;
//            System.out.println(answer);
            int guess = scan.nextInt();
            while (guess != answer && chances > 1) {
                chances = chances -1;
                if (guess < answer) {
                    System.out.println(guess + "猜小了！还有"+chances+"次机会！请猜一个1-100之间的整数：");
                } else if (guess > answer) {
                    System.out.println(guess + "猜大了！还有"+chances+"次机会！请猜一个1-100之间的整数：");
                }
                guess = scan.nextInt();
            }
            if(guess == answer) {
                System.out.println("猜对啦！");
            }
            System.out.println("重新玩一次吗？（y/n)?");
            playAgain = scan.next();
        }while (playAgain.equalsIgnoreCase("y"));
        scan.close();

    }
}
